home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / CPP100.ZIP / CPPLGEN2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  8.0 KB  |  241 lines

  1. /*****************************************************************************/
  2. /*       (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved         */
  3. /*****************************************************************************/
  4. /*    This source-code is NOT public domain nor Freeware, this is part of    */
  5. /*              'The C Programming Package' which is Shareware.              */
  6. /*   If you use this code, please register and get a free Full-VGA version   */
  7. /*****************************************************************************/
  8.                                /*--------------------*
  9.                                 *     CPPLGEN2.C     *
  10.                                 *   Mouse programs   *
  11.                                 *    & utilities     *
  12.                                 *--------------------*/
  13.  
  14.  /* Included Files */
  15.  # include <stdio.h>
  16.  # include <io.h>
  17.  # include <dos.h>
  18.  # include <fcntl.h>
  19.  # include <bios.h>
  20.  # include <stdlib.h>
  21.  # include <conio.h>
  22.  # include <graphics.h>
  23.  
  24.  /* Global Variables */
  25.  extern int i,j,k,l,m,n,t,x,x1,x2,xm,xms,y,y1,y2,ym,yms,z,soundvar,returning;
  26.  extern int colour1,colour2,colour3,colour4,colour5,cardtype,divx,divy;
  27.  extern int menu0,menu1,menu2,menu3,menu4,menu5,menu6,menu7,menu8;
  28.  extern int pfdiv,pfserv,pfhelp,menu9,menu10;
  29.  extern unsigned char c0,c1,nc1[],trashcan[],trashret[],name[];
  30.  
  31.  /*----------------------*
  32.   * GAMES WITH THE MOUSE *
  33.   *----------------------*/
  34.   int games_with_the_mouse()
  35.     {
  36.       returning=check_the_mouse();
  37.       if(returning==1){
  38.         show_the_mouse();            /*  limit_the_mouse(); */
  39.     return(1);
  40.       }
  41.       else{
  42.         /* The mouse is not connected or the driver is not loaded */
  43.         warning(" Mouse not connected "," or driver not loaded "," Press <Enter> ","","");
  44.     return(0);
  45.       }
  46.     }
  47.  /*---------------*
  48.   * MOUSE FACTORS *
  49.   *---------------*/
  50.   void mouse_factors()
  51.     {
  52.       if((cardtype<4)||(cardtype==9)||(cardtype==10)){
  53.     divx=8;                        divy=8;
  54.     return;
  55.       }
  56.       if((cardtype>3)&&(cardtype<7)){
  57.     divx=8;                        divy=14;
  58.     return;
  59.       }
  60.       if(cardtype==7){
  61.     /* ? Hercules 720x348 ? */
  62.     divx=9;                        divy=12;
  63.     return;
  64.       }
  65.       if(cardtype==8){
  66.     divx=8;                        divy=16;
  67.     return;
  68.       }
  69.       if(cardtype==11){
  70.     divx=9;                        divy=14;
  71.     return;
  72.       }
  73.     }
  74.  /*----------------------------*
  75.   * READ VIDEO CARD *
  76.   *----------------------------*/
  77.   void read_video_card()
  78.     {
  79.       int graphdriver,graphmode,errorcode;
  80.       detectgraph(&graphdriver,&graphmode);
  81.       errorcode=graphresult();
  82.       if(errorcode !=0){
  83.         warning(" Reading error "," of the videocard ",""," Press a Key ","");
  84.         return;
  85.       }
  86.       cardtype=0;
  87.       /* 320x200x4c CGA */
  88.       if((graphdriver==1)&&(graphmode<4))        cardtype=1;
  89.       /* 640x200x2c CGA */
  90.       if((graphdriver==1)&&(graphmode==4))       cardtype=2;
  91.       /* 320x200x4c MCGA */
  92.       if((graphdriver==2)&&(graphmode<4))        cardtype=1;
  93.       /* 640x200x2c MCGA */
  94.       if((graphdriver==2)&&(graphmode==4))       cardtype=2;
  95.       /* 640x480x2c MCGA */
  96.       if((graphdriver==2)&&(graphmode==5))       cardtype=10;
  97.       /* 640x200x16c EGA */
  98.       if((graphdriver==3)&&(graphmode==0))       cardtype=3;
  99.       /* 640x350x16c EGA */
  100.       if((graphdriver==3)&&(graphmode==1))       cardtype=4;
  101.       /* 640x200x16c EGA 64 */
  102.       if((graphdriver==4)&&(graphmode==0))       cardtype=3;
  103.       /* 640x350x4c EGA 64 */
  104.       if((graphdriver==4)&&(graphmode==1))       cardtype=5;
  105.       /* 640x350x2c EGA MONO */
  106.       if((graphdriver==5)&&(graphmode==3))       cardtype=6;
  107.       /* 720x348x2c Hercules MONO */
  108.       if((graphdriver==7)&&(graphmode==0))       cardtype=7;
  109.       /* 320x200x4c ATT 400 */
  110.       if((graphdriver==8)&&(graphmode<4))        cardtype=1;
  111.       /* 640x200x2c ATT 400 */
  112.       if((graphdriver==8)&&(graphmode==4))       cardtype=2;
  113.       /* 640x400x2c ATT 400 */
  114.       if((graphdriver==8)&&(graphmode==5))       cardtype=8;
  115.       /* 640x200x16c VGA */
  116.       if((graphdriver==9)&&(graphmode==0))       cardtype=3;
  117.       /* 640x350x16c VGA */
  118.       if((graphdriver==9)&&(graphmode==1))       cardtype=4;
  119.       /* 640x480x16c VGA */
  120.       if((graphdriver==9)&&(graphmode==2))       cardtype=9;
  121.       /* 720x350x2c PC 3270 */
  122.       if((graphdriver==10)&&(graphmode==0))      cardtype=11;
  123.       if(cardtype==0){
  124.         warning(" Reading error "," of the videocard ",""," Press a Key ","");
  125.         return;
  126.       }
  127.       /* As the mouse co-ordinates are in pixels */
  128.       /* we calculate the needed factors         */
  129.       mouse_factors();
  130.     }
  131.  /*----------------------------------*
  132.   * RE-INIT INIT VARIABLES  *
  133.   *----------------------------------*/
  134.   void re_init_init_variables()
  135.     {
  136.       /* The window is the whole screen */
  137.       x1=1;                            x2=80;
  138.       y1=1;                            y2=25;
  139.       /* The mouse is put in the upper-left corner */
  140.       xms=2;                           yms=1;
  141.       /* Put the handles to -1 to indicate that these files */
  142.       /* are not open (test case) */
  143.       pfdiv=-1;                        pfserv=-1;
  144.       pfhelp=-1;
  145.       /* No menu is displayed */
  146.       menu0=0;                         menu1=1;
  147.       menu2=1;                         menu3=1;
  148.       menu4=1;                         menu5=1;
  149.       menu6=1;                         menu7=1;
  150.       menu8=1;                         menu9=1;
  151.       menu10=1;
  152.  
  153.     }
  154.  /*----------------------------------*
  155.   * RE-INIT PROGRAM VARIABLES *
  156.   *----------------------------------*/
  157.   void re_init_program_variables()
  158.     {
  159.       randomize();                     soundvar=1;
  160.       /* We have to init the other data */
  161. /*      strcpy(name,"                   ");  name[19]=0x00;   */
  162.  
  163.     }
  164.  /*----------------------*
  165.   * INIT PROGRAM *
  166.   *----------------------*/
  167.   int program_init()
  168.     {
  169.       /* init the variables */
  170.       re_init_init_variables();
  171.       re_init_program_variables();
  172.       read_video_card();
  173.       if((read_hardware_config())==0)  return(0);
  174.       return(1);
  175.     }
  176.  /*----------------------------------------*
  177.   * GET OR CHANGE A WORD (xx,yy,nbcar) *
  178.   *----------------------------------------*/
  179.   int get_or_change_a_word(xx,yy,nbcar)
  180.     int xx,yy,nbcar;
  181.     {
  182.       /* First copy the sent word */
  183.       strcpy(trashret,trashcan);
  184.       /* Then fill it with spaces */
  185.       sound1();                          j=strlen(trashcan);
  186.       for(i=j; i<(nbcar-1); i++)         trashret[i]=0x20;
  187.       i=0;
  188.       nc1[0]=0x20;                       nc1[1]=0x00;
  189.       while(1){
  190.         textattr(colour4);
  191.         gotoxy(xx,yy);                   cputs(trashret);
  192.         textattr(colour5);               nc1[0]=trashret[i];
  193.     gotoxy((xx+i),yy);                   cputs(nc1);
  194.     c0=getch();
  195.     if(c0==27){
  196.           blank_line_25();               return(0);
  197.     }
  198.     if(c0==13)                           break;
  199.     if(c0==0){
  200.       c1=getch();
  201.       if(c1==83){
  202.         /* Suppression */
  203.             for(j=i; j<nbcar; j++)       trashret[j]=trashret[j+1];
  204.             trashret[nbcar-1]=0x20;
  205.       }
  206.       if(c1==77){
  207.             /* Right arrow */
  208.         if(i<nbcar-2)              i++;
  209.       }
  210.       if(c1==75){
  211.             /* Left arrow */
  212.         if(i>0)                    i--;
  213.       }
  214.       if(c1==71){
  215.             /* Beginning */
  216.         i=0;
  217.       }
  218.       if(c1==79){
  219.             /* End */
  220.         i=nbcar-1;
  221.       }
  222.     }
  223.     if((c0>31)&&(c0<179)){
  224.           /* legal char */
  225.           nc1[0]=c0;                   trashret[i]=c0;
  226.       if(i<nbcar-1)                i++;
  227.     }
  228.     if(c0==8){
  229.           /* Go backward */
  230.       i--;
  231.           for(j=i; j<(nbcar-1); j++)   trashret[j]=trashret[j+1];
  232.           trashret[nbcar-1]=0x20;
  233.     }
  234.        }
  235.       /* If we entered more chars than allowed, we cut there the word */
  236.       blank_line_25();             trashret[nbcar]=0x00;
  237.       return(1);
  238.     }
  239. /* End of the Module *//*-----------------*/
  240.  
  241.